package com.qys.livesMall.anchor.controller.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.anchor.model.dto.lives.sys.LivesGiftSaveDTO;
import com.qys.livesMall.anchor.model.dto.task.sys.SysLivesGiftPageDTO;
import com.qys.livesMall.anchor.model.vo.lives.sys.SysLivesGiftListVO;
import com.qys.livesMall.anchor.service.AnchorLivesGiftService;
import com.qys.livesMall.common.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 直播礼物表 前端控制器
 * </p>
 *
 * @author wzy
 * @since 2023-06-21
 */
@RestController
@Tag(name = "后台管理-直播礼物")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/sys/anchor/lives/gift")
public class SysAnchorLivesGiftController {


    private final AnchorLivesGiftService livesGiftService;


    @PostMapping("/list")
    @Operation(summary = "分页查询直播礼物列表")
    public R<Page<SysLivesGiftListVO>> list(@RequestBody SysLivesGiftPageDTO queryDTO) {
        return R.ok(livesGiftService.pageBySys(queryDTO));
    }

    @PostMapping("/add")
    @Operation(summary = "新增直播礼物列表")
    public R<Void> add(@RequestBody @Validated LivesGiftSaveDTO saveDTO) {
        livesGiftService.saveOrUpdate(saveDTO);
        return R.ok();
    }

    @PutMapping("/edit")
    @Operation(summary = "编辑直播礼物列表")
    public R<Void> edit(@RequestBody @Validated LivesGiftSaveDTO saveDTO) {
        livesGiftService.saveOrUpdate(saveDTO);
        return R.ok();
    }

    @Operation(
            summary = "删除直播礼物",
            parameters = {
                    @Parameter(name = "id", description = "直播礼物id")
            }
    )
    @DeleteMapping(value = "/delete/{id}")
    public R<Void> deleteById(@PathVariable Long id) {
        livesGiftService.deleteById(id);
        return R.ok();
    }


    @PutMapping("/shelves/{id}")
    @Operation(
            summary = "上架下架",
            parameters = {
                    @Parameter(name = "id", description = "直播礼物id")
            }
    )
    public R<Void> shelves(@PathVariable("id") Long id) {
        livesGiftService.shelves(id);
        return R.ok();
    }


    @GetMapping("/{id}")
    @Operation(
            summary = "根据id查询直播礼物信息",
            parameters = {
                    @Parameter(name = "id", description = "直播礼物id")
            }
    )
    public R<SysLivesGiftListVO> queryById(@PathVariable Long id) {
        return R.ok(livesGiftService.queryById(id));
    }


}
